<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MVCWeb.Models.DocCategory>>" %>

<%@ Register Src="~/Views/Menu/MainMenu.ascx" TagName="MainMenu" TagPrefix="mmuc" %>

<%@ Register Src="~/Views/Shared/LogOnUserControl.ascx" TagName="LogOnUserControl" TagPrefix="louc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>Admin: Index Of Legislative Documents</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <louc:LogOnUserControl ID="LogOnUserControl1" runat="server" />
    <!-- BEGIN: MainMenu -->
    <mmuc:MainMenu ID="MainMenu1" runat="server" />
    <!-- END: MainMenu -->
    <h2>
        Admin: Index Of Legislative Documents</h2>

    <script language="javascript" type="text/javascript">
        function deleteRecord(recordId) {
            if (confirm("Are you sure to delete this document?")) {
                // Perform delete
                var action = '<%= Url.Action("Delete", "Doc") %>/' + recordId;
                var request = new Sys.Net.WebRequest();
                request.set_httpVerb("POST");
                request.set_url(action);
                request.add_completed(deleteCompleted);
                request.invoke();
            }
        }

        function deleteCompleted() {
            // Reload page  
            window.location.reload();
        }    
    </script>

    <% foreach (var category in Model)
       { %>
    <table id="document">
        <tr>
            <th style="width: 1%">
            </th>
            <th style="width: 1%">
            </th>
            <th style="width: 100%">
                Title
            </th>
            <th>
                Modified Date
            </th>
            <th>
                Size (Kb)
            </th>
            <th>
            </th>
        </tr>
        <% foreach (var item in category.Docs)
           { %>
        <tr>
            <td style="white-space: nowrap">
                <a href='<%= Url.Action("EditLegislativeDoc", "Doc", new { id = item.DocId })%>'>Edit </a>
            </td>
            <td style="white-space: nowrap">
                <a onclick="deleteRecord(<%= item.DocId %>)" href="JavaScript:void(0)">Delete </a>
            </td>
            <td>
                <%= Html.Encode(item.Name)%>
            </td>
            <td>
                <%= Html.Encode(item.ModifiedDate.Value.ToShortDateString()) %>
            </td>
            <td>
                <%= (Convert.ToDouble(Html.Encode(item.Size)) / 1024).ToString("N2") %>
            </td>
            <td>
                <a target="_blank" href='<%= item.URLLink %>'>Download</a>
            </td>
        </tr>
        <% }%>
    </table>
    <%} %>
</asp:Content>
